package cn.codenest.db;

import org.apache.kafka.clients.consumer.ConsumerRecord;

import java.util.concurrent.ConcurrentHashMap;

/**
 * @author ：Hyman
 * @date ：Created in 2021/7/12 19:21
 * @description：
 * @modified By：
 * @version: $
 */
public class DemoDB {
    /**
     * create by: Hyman
     * description: 用来模拟存储ConsumerRecord
     * create time: 2021/7/12
     */
    public static ConcurrentHashMap<String, ConsumerRecord> consumerRecords = new ConcurrentHashMap(128);

    public static ConcurrentHashMap<String, Long> offsets = new ConcurrentHashMap(128);

    public static String getKey(String topic, int partition) {
        String key = String.format("%s-%d", topic, partition);
        return key;
    }

    public static void commitDBTransaction() {
        if (consumerRecords.isEmpty() == false ||
                offsets.isEmpty() == false) {
            System.out.println("开始提交数据库事务。");
            System.out.println("数据库事务提交成功。");
            consumerRecords.clear();
            offsets.clear();
        }

    }
}
